package com.blockmeta.bbs.businesslibrary.util.navigation.impl;

import android.net.Uri;
import android.text.TextUtils;

import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.eventbus.XGPushEvent;
import com.blockmeta.bbs.businesslibrary.util.navigation.SimpleDeepLinkStrategy;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author AirThor
 * @date 2019/7/25.
 * "blockmeta://activity"
 */
public class ActivityStrategy extends SimpleDeepLinkStrategy {
    @Override
    public Uri uriTransformer(Uri uri) {
        if (TextUtils.isEmpty(uri.getQueryParameter("tid"))){
            return Uri.parse("blockmeta://activity"+RouterPath.MAIN_ACTIVITY);
        }
        return Uri.parse("blockmeta://activity"+ RouterPath.ACTIVE_DETAIL_ACTIVITY);
    }

    @Override
    public Map<String, String> navigationParams(Uri uri) {
        HashMap<String,String> params = new HashMap<>(2);
        params.put(Constant.ZERO,uri.getQueryParameter("tid"));
        return params;
    }

    @Override
    public boolean needSendEvents(Uri uri) {
        String tid = uri.getQueryParameter("tid");
        if (TextUtils.isEmpty(tid)) {
            EventBus.getDefault().postSticky(new XGPushEvent(2, 2, XGPushEvent.ACTIVITY, null));
            return true;
        }
        return false;
    }
}
